﻿using System.Collections.Generic;
using SWD = System.Web.Services.Description;

namespace MockingBird.Wsdl.Parser
{
    using System.Xml;

    public class OperationMessage
    {
        public string Name { get; private set; }
        public List<string> PartNames { get; private set; }
        public List<OperationMessagePart> Parts { get; private set; }
        public string MessageName { get; private set; }
        public string MessageNamespace { get; private set; }
        public XmlQualifiedName MessageQName { get; private set; }

        public OperationMessage(SWD.ServiceDescription desc, SWD.OperationMessage msg)
        {
            this.Name = msg.Message.Name;
            Parts = new List<OperationMessagePart>(desc.Messages[this.Name].Parts.Count);
            PartNames = new List<string>();

            foreach (SWD.MessagePart part in desc.Messages[this.Name].Parts)
            {
                OperationMessagePart msgPart = new OperationMessagePart(desc, part);
                Parts.Add(msgPart);
                PartNames.Add(msgPart.Name);

            }

            //set the MessageName and Namespace from the default part name
            //TBC: This logic needs to be revisited to establish why we only care about
            //single parts
            this.MessageName = this.Parts[0].ElementName;
            this.MessageNamespace = this.Parts[0].ElementNamespace;
            this.MessageQName = new XmlQualifiedName(this.MessageName, this.MessageNamespace);
        }


    }
}
